home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS02.ADF
/
IFF
/
old2ilbm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-30
|
8KB
|
255 lines
/***************************************************************************
* Old2ILBM.c -- Convert old LoRes 5-plane .pic file to ILBM file
* by Carolyn Scheppner CBM 01/86
* Using IFF rtns by J.Morrison and S.Shaw of Electronic Arts
*
* Notes: 1. Headers changed to allow compilation under 1.0
* 2. This program does not create a .info file for
* the new IFF file. If need an icon for the file,
* (ex. for Graphicraft), copy the .info file
* for another picture and rename it to your
* IFF file name with a .info suffix.
*
* Alink information:
* FROM B:LStartup.obj,SRC:Old2ILBM.o,SRC:iffw.o,SRC:ilbmw.o,SRC:packer.o
* TO SRC:Old2ILBM
* LIBRARY B:lc.lib,B:amiga.lib
*
* Note: B: assigned to libs/ and SRC: assigned to dir of .o files
*
***************************************************************************/
#include <exec/types.h>
#include <exec/exec.h>
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <graphics/copper.h>
#include <graphics/gels.h>
#include <graphics/regions.h>
#include <hardware/blit.h>
#include <devices/keymap.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <libraries/dos.h>
#include <iff/ilbm.h>
#define bufSize 512
#define DEPTH 5
#define WIDTH 320
#define HEIGHT 200
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
ULONG DosBase;
struct BitMap oldBitMap;
struct OldHeader {
WORD filetype; /* 0000 = pic */
WORD compression;
WORD bitplanes; /* usually stored as 0000 */
WORD mini;
ULONG datasize; /* 0000FA00 for 320x200, 5 planes */
WORD xorig;
WORD yorig;
WORD height;
WORD width; /* in bytes ! */
} oldHeader = {0};
struct OldColor { /* Old file format */
BYTE red;
BYTE green;
BYTE blue;
BYTE pad;
} oldColor = {0};
WORD colorTable[32]; /* Amiga color table format */
int i;
/* main() */
void main(argc,argv)
int argc;
char **argv;
{
LONG oldfile;
LONG newfile;
IFFP iffp = NO_FILE;
WORD colortemp;
int planebytes;
printf("\nOLd2ILBM - Converts old IG 320x200 5-plane .pic to IFF\n\n");
if (argc < 3)
printf(" Usage: 'Old2ILBM oldfilename newfilename'\n\n");
else
{
if ((IntuitionBase =
(struct IntuitionBase *)OpenLibrary("intuition.library",0))==NULL)
cleanexit(-1);
if ((GfxBase =
(struct GfxBase *)OpenLibrary("graphics.library",0))==NULL)
cleanexit(-1);
if ((DosBase = OpenLibrary("dos.library",0))==NULL)
cleanexit(-1);
if ((oldfile = Open(argv[1], MODE_OLDFILE))==NULL)
printf("Can't open %s\n\n",argv[1]);
else
{
if ((newfile = Open(argv[2], MODE_NEWFILE))==NULL)
printf("Can't open %s\n\n",argv[2]);
else
{
InitBitMap(&oldBitMap,DEPTH,WIDTH,HEIGHT);
for(i=0; i < DEPTH; i++)
{
if((oldBitMap.Planes[i] =
(PLANEPTR)AllocRaster(WIDTH,HEIGHT)) == NULL)
{
printf("Can't allocate RAM for bitmap.\n");
cleanexit(-1);
}
}
printf(" Note: This program does not create a .info file\n");
printf(" for the IFF picture file. If you need an\n");
printf(" icon, copy a picture .info file from your\n");
printf(" IFF paint package and give it the same name\n");
printf(" as your picture file adding a .info suffix.\n\n");
printf("\nConverting '%s' to IFF '%s'...\n\n", argv[1],argv[2]);
Read(oldfile,(BYTE *)&oldHeader,20);
if((oldHeader.width != 40)||(oldHeader.height != 200))
{
printf("Warning: Old pic x/y sizes are hex %x by %x.\n",
oldHeader.width,oldHeader.height);
}
for (i=0; i < (1<<DEPTH); i++)
{
colortemp = 0;
Read(oldfile,(BYTE *)&oldColor,4);
colortemp = oldColor.red;
colortemp = colortemp << 4;
colortemp |= oldColor.green;
colortemp = colortemp << 4;
colortemp |= oldColor.blue;
colorTable[i] = colortemp;
}
planebytes = (int)((WIDTH/8)*HEIGHT);
for(i=0; i < DEPTH; i++)
{
Read(oldfile,oldBitMap.Planes[i],planebytes);
}
Write(newfile,"x",1); /* so Seek to beginning works ? */
iffp = PutPicture(newfile, &oldBitMap, &colorTable[0]);
Close(newfile);
}
Close(oldfile);
}
cleanup();
}
}
cleanexit(error)
int error;
{
cleanup();
exit(error);
}
cleanup()
{
for (i=0; i < DEPTH; i++)
{
if(oldBitMap.Planes[i] != NULL)
FreeRaster(oldBitMap.Planes[i],WIDTH,HEIGHT);
}
if (DosBase) CloseLibrary(DosBase);
if (GfxBase) CloseLibrary(GfxBase);
if (IntuitionBase) CloseLibrary(IntuitionBase);
}
/** PutPicture() ***********************************************************
*
* Put a picture into an IFF file.
* This procedure calls PutAnILBM, passing in an <x, y> location of <0, 0>,
* a NULL mask, and a locally-allocated buffer. It also assumes you want to
* write out all the bitplanes in the BitMap.
*
***************************************************************************/
Point2D nullPoint = {0, 0};
IFFP PutPicture(file, bitmap, colorMap)
LONG file; struct BitMap *bitmap; WORD *colorMap;
{
BYTE buffer[bufSize];
return( PutAnILBM(file, bitmap, NULL,
colorMap, bitmap->Depth, &nullPoint,
buffer, bufSize) );
}
/** PutAnILBM() ************************************************************
*
* Write an entire BitMap as a FORM ILBM in an IFF file.
* This version works for any display mode (C. Scheppner).
*
* Normal return result is IFF_OKAY.
*
* The utility program IFFCheck would print the following outline of the
* resulting file:
*
* FORM ILBM
* BMHD
* CMAP
* BODY (compressed)
*
***************************************************************************/
#define CkErr(expression) {if (ifferr == IFF_OKAY) ifferr = (expression);}
IFFP PutAnILBM(file, bitmap, mask, colorMap, depth, xy, buffer, bufsize)
LONG file; struct BitMap *bitmap; BYTE *mask; WORD *colorMap;
UBYTE depth; Point2D *xy;
BYTE *buffer; LONG bufsize;
{
BitMapHeader bmHdr;
GroupContext fileContext, formContext;
IFFP ifferr;
WORD pageWidth, pageHeight;
pageWidth = (bitmap->BytesPerRow) << 3;
pageHeight = bitmap->Rows;
ifferr = InitBMHdr(&bmHdr, bitmap, mskNone,
cmpByteRun1, 0, pageWidth, pageHeight);
/* You could write an uncompressed image by passing cmpNone instead
* of cmpByteRun1 to InitBMHdr. */
bmHdr.nPlanes = depth; /* This must be <= bitmap->Depth */
if (mask != NULL) bmHdr.masking = mskHasMask;
bmHdr.x = xy->x; bmHdr.y = xy->y;
CkErr( OpenWIFF(file, &fileContext, szNotYetKnown) );
CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext));
CkErr( PutBMHD(&formContext, &bmHdr) );
CkErr( PutCMAP(&formContext, colorMap, depth) );
CkErr( PutBODY(&formContext, bitmap, mask, &bmHdr, buffer, bufsize) );
CkErr( EndWGroup(&formContext) );
CkErr( CloseWGroup(&fileContext) );
return( ifferr );
}